package com.yanqu.road.server.timer.banquet;

import com.yanqu.road.entity.banquet.UserBanquetData;
import com.yanqu.road.entity.banquet.UserBanquetMember;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.banquet.BanquetMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.executor.GeneralTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Map;

public class BanquetSyncMemberTask extends GeneralTask {

    protected Logger logger = LogManager.getLogger(BanquetSyncMemberTask.class.getName());

    private long userId;
    private String banquetId;
    private int sendTime;
    private int memNum;
    private int page;


    public BanquetSyncMemberTask(long userId, String banquetId, int sendTime, int memNum, int page) {
        this.userId = userId;
        this.banquetId = banquetId;
        this.sendTime = sendTime;
        this.memNum = memNum;
        this.page = page;
    }

    @Override
    public void doRun() {
        /*try {
            Thread.sleep(3000);
        }catch ( Exception $e){
            logger.error($e);
        }*/
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        if (player != null) {
            for(int i=page;i<=sendTime;i++){
                UserBanquetData banquet = BanquetMgr.getBanquet(banquetId);
                Map<Long, UserBanquetMember> userBanquetMemberMap = BanquetMgr.getBanquetMemberMap(banquetId,memNum,i);
                if(!BanquetMgr.syncBanquetMember(player,banquet,userBanquetMemberMap)){
                    logger.error("break:index={}-sendTime={}",i,sendTime);
                    break;
                }
            }
            logger.info("over:sendTime={}",sendTime);
        }
    }
}
